<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@page import="model.UserModel" %>
   <%
   	UserModel u = (UserModel) session.getAttribute("user_session");
   %>
Ext.define('Ext.app.ContactForm', {
    extend: 'Ext.form.Panel',
    requires: [
     'Ext.data.ArrayStore',
     'Ext.data.reader.Array',
     'Ext.form.field.ComboBox',
     'Ext.form.field.Date'
    ],
    username: 'Tài khoản*',
    email: 'Email*',
    password: 'Mật khẩu*',
    newPassword: 'Mật khẩu mới',
    confirmPassword: 'Nhập lại mật khẩu mới',
    save: 'Save',
    initComponent : function(config) {
        Ext.apply(this, {
            url: 'save-form.php',
            frame: true,
            width: 410,
            defaultType: 'textfield',
            defaults: {
                width: 390
            },
            items: [{
                    fieldLabel: this.username,
                    name: 'username',
                    value: '<%=u.getUsername() %>',
                    allowBlank:false
                },{
                    fieldLabel: this.email,
                    name: 'email',
                    value: '<%=u.getEmail() %>',
                    allowBlank:false,
                    vtype:'email'
                },{
                    fieldLabel: this.password,
                    name: 'password',
                    value: '********',
                    allowBlank:false,
                },{
                    fieldLabel: this.newPassword,
                    name: 'newpassword',
                },{
                    fieldLabel: this.confirmPassword,
                    name: 'confirmpassword'
                }
            ],

            buttons: [{
                text: this.save,
                handler: function() {
                	var form = this.up('form').getForm();
                    if (form.isValid()) {
                        Ext.Ajax.request({
					    url: 'UpdateSystem',
					    method: 'post',
					    params: {
					        username: form.getValues().username,
					        email: form.getValues().email,
					        password: form.getValues().password,
					        newpassword: form.getValues().newpassword,
					        confirm: form.getValues().confirmpassword
					    },
					    success: function(response){
					        var text = response.responseText;
					        Ext.MessageBox.alert('Thông báo', text);
					    }
					});
                    }
                    //console.log(form.getValues().username);
                }
            }]
        });

        this.callParent(arguments);
    }
});


Ext.onReady(function(){
    var simple = Ext.create('Ext.app.ContactForm', {});
    simple.render(document.body);
});
